﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Jage.Common;

namespace Jage.Data
{
    public class JageDb
    {

        private static JageDatabase _default;

        /// <summary>
        /// Singleton of database in default location as configured.
        /// </summary>
        public static JageDatabase Default
        {
            get
            {
                if (_default == null) 
                    _default = Get(Path.GetFullPath(Configuration.Default.DatabaseFilename));
                return _default;
            }
        }

        public static JageDatabase Get(string filename)
        {
            if (File.Exists(filename))
            {
                return new JageDatabase(String.Format("metadata=res://*/Jage.csdl|res://*/Jage.ssdl|res://*/Jage.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=\"Data Source={0}\"", filename));
            }
            else
            {
                throw new FileNotFoundException(String.Format("Database file \"{0}\" could not be found.", filename));
            }
        }

    }
}
